/* global Cesium */

const DistanceDisplayCondition = Cesium.DistanceDisplayCondition;
const defaultValue = Cesium.defaultValue;

class TargetStyle {
    constructor() {
        this.color = '#FFFFFF';
        this.selectedColor = 'GREEN';
        this.pointSize = 2;
        this.pointLineWidth = 0;
        this.pointLineColor = '#FFFFFF';
        this.pointDisplayCondition = new DistanceDisplayCondition(10000);
        this.fontSize = 12;
        this.fontColor = '#FFFFFF';
        this.font = '微软雅黑';
        this.fontBackgroundColor = '#000000';
        this.labelDisplayCondition = new DistanceDisplayCondition(0, 1000);
        this.labelLineColor = '#FFFFFF';
        this.iconUrl = 'data/img/民用船只.png';
        this.iconSize = 32;
        this.iconDisplayCondition = new DistanceDisplayCondition(1000, 10000);
        this.modelUrl = '';
        this.modelDisplayCondition = new DistanceDisplayCondition(0, 1000);
        this.modelMaximumScale = 200;
        this.modelMinimumPixelSize = 100;
        this.markColor = '#FF0000';
        this.markRadius = 800;
        this.markDisplayCondition = new DistanceDisplayCondition(0, 10000);
        this.trackLineWidth = 2;
        this.trackLineColor = '#FF0000';
        this.labelOffsetX = 0;
        this.labelOffsetY = -0;
        this.showBackground = true;
    }
    /**
     * 默认样式
     */
    static DefaultStyle() {
        return new TargetStyle();
    }
    /**
     * 将样式保存为json
     * @method toJson
     *
     */
    static toJson(style) {
        let config = {};
        config.color = style.color;
        config.pointSize = style.pointSize;
        config.pointLineWidth = style.pointLineWidth;
        config.fontSize = style.fontSize;
        config.pointLineColor = style.pointLineColor;
        config.fontColor = style.fontColor;
        config.font = style.font;
        config.fontBackgroundColor = style.fontBackgroundColor;
        config.labelLineColor = style.labelLineColor;
        config.iconUrl = style.iconUrl;
        config.iconSize = style.iconSize;
        config.modelUrl = style.modelUrl;
        config.modelMaximumScale = style.modelMaximumScale;
        config.modelMinimumPixelSize = style.modelMinimumPixelSize;
        config.trackLineWidth = style.trackLineWidth;
        config.trackLineColor = style.trackLineColor;
        config.labelOffsetX = style.labelOffsetX;
        config.labelOffsetY = style.labelOffsetY;
        config.pointDisplayCondition = [
            style.pointDisplayCondition.near,
            style.pointDisplayCondition.far,
        ];
        config.iconDisplayCondition = [
            style.iconDisplayCondition.near,
            style.iconDisplayCondition.far,
        ];
        config.labelDisplayCondition = [
            style.labelDisplayCondition.near,
            style.labelDisplayCondition.far,
        ];
        config.modelDisplayCondition = [
            style.modelDisplayCondition.near,
            style.modelDisplayCondition.far,
        ];
        return config;
    }
    /**
     * 加载样式
     * @method fromJson
     * @param style 样式对象
     *
     */
    static fromJson(style) {
        let newStyle = new TargetStyle();
        newStyle.color = defaultValue(style.color, newStyle.color);
        newStyle.pointSize = defaultValue(style.pointSize, newStyle.pointSize);
        newStyle.pointLineWidth = defaultValue(style.pointLineWidth, newStyle.pointLineWidth);
        newStyle.fontSize = defaultValue(style.fontSize, newStyle.fontSize);
        newStyle.pointLineColor = defaultValue(style.pointLineColor, newStyle.pointLineColor);
        newStyle.fontColor = defaultValue(style.fontColor, newStyle.fontColor);
        newStyle.font = defaultValue(style.font, newStyle.font);
        newStyle.fontBackgroundColor = defaultValue(
            style.fontBackgroundColor,
            newStyle.fontBackgroundColor
        );
        newStyle.labelLineColor = defaultValue(style.labelLineColor, newStyle.labelLineColor);
        newStyle.iconUrl = defaultValue(style.iconUrl, newStyle.iconUrl);
        newStyle.iconSize = defaultValue(style.iconSize, newStyle.iconSize);
        newStyle.modelUrl = defaultValue(style.modelUrl, newStyle.modelUrl);
        newStyle.modelMaximumScale = defaultValue(
            style.modelMaximumScale,
            newStyle.modelMaximumScale
        );
        newStyle.modelMinimumPixelSize = defaultValue(
            style.modelMinimumPixelSize,
            newStyle.modelMinimumPixelSize
        );
        newStyle.trackLineWidth = defaultValue(style.trackLineWidth, newStyle.trackLineWidth);
        newStyle.trackLineColor = defaultValue(style.trackLineColor, newStyle.trackLineColor);
        newStyle.labelOffsetX = defaultValue(style.labelOffsetX, newStyle.labelOffsetX);
        newStyle.labelOffsetY = defaultValue(style.labelOffsetY, newStyle.labelOffsetY);
        if (style.pointDisplayCondition) {
            newStyle.pointDisplayCondition = new DistanceDisplayCondition(
                style.pointDisplayCondition[0],
                style.pointDisplayCondition[1]
            );
        }
        if (style.iconDisplayCondition) {
            newStyle.iconDisplayCondition = new DistanceDisplayCondition(
                style.iconDisplayCondition[0],
                style.iconDisplayCondition[1]
            );
        }
        if (style.labelDisplayCondition) {
            newStyle.labelDisplayCondition = new DistanceDisplayCondition(
                style.labelDisplayCondition[0],
                style.labelDisplayCondition[1]
            );
        }
        if (style.modelDisplayCondition) {
            newStyle.modelDisplayCondition = new DistanceDisplayCondition(
                style.modelDisplayCondition[0],
                style.modelDisplayCondition[1]
            );
        }
        return newStyle;
    }
}
export default TargetStyle;
